package ooday03;
/** 引用类型数组*/
public class RefArrayDemo {
    public static void main(String[] args) {
        // 若想访问引用数组元素的属性/行为时，需要打点访问
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",2,"黑");
        dogs[1] = new Dog("小白",1,"白");
        dogs[2] = new Dog("小灰",3,"灰");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i = 0;i< dogs.length;i++){
            System.out.println(dogs[i].name);
            dogs[i].eat();
        }




        // 给引用类型数组元素赋值，需要new个对象
        /*
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",2,"黑");
        dogs[1] = new Dog("小白",1,"白");
        dogs[2] = new Dog("小灰",3,"灰");

        Chick[] chick = new Chick[2];
        chick[0] = new Chick("小花",1,"花");
        chick[1] = new Chick("大花",2,"花");
         */

        // 数组的定义
        /*
        Dog[] dogs  = new Dog[3];
        Chick[] chicks = new Chick[3];
        Fish[] fish = new Fish[3];
         */

    }
}
